#!/usr/bin/env python
import os, cPickle
from datetime import datetime, timedelta

def main():
    # List all files
    allfiles = os.listdir('../site_data/')
    nws_files = [f for f in allfiles if 'NWS' in f]
    #print nws_files
    for file in nws_files:
        # Load the file
        print "Processing ", file
        f = open('../site_data/%s' % file,'r')
        oldd = cPickle.load(f)
        f.close()
        # Move out the old file
        os.system('mv ../site_data/%s ../temp/' % file)

        # Create a new dictionary
        newd = {}
        for date in oldd.keys():
            newd[date] = {}
            newd[date]['high'] = float(oldd[date]['high'])
            newd[date]['low'] = float(oldd[date]['low'])
            newd[date]['wind'] = float(oldd[date]['wind'])
            newd[date]['precip'] = float(oldd[date]['precip'])

        # Dump the new dictionary
        fout = open('../site_data/%s' % file, 'w')
        cPickle.dump(newd,fout)
        fout.close()





if __name__ == '__main__':
    main()
